﻿using System;
using System.Windows;
using System.Windows.Automation;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using QuickUIT.Controls;
using QuickUIT.Input;

namespace QuickUIT.Tests
{
    [TestClass]
    public class UIControlTests
    {
        private BaseState _baseState;

        [TestInitialize]
        public void TestSetup()
        {
            _baseState = new BaseState(TestUtilities.GetTestApplicationFileName(), "@Name='QuickUIT Test Application'");
            _baseState.Execute();
        }

        [TestMethod]
        public void ShouldGetAutomationIdProperty()
        {
            var window = new UIWindow("@Name='QuickUIT Test Application'");
            UIControl button = window.UIControl("[@ControlType='Button'][@Name='Button']");
            Assert.AreEqual("button1", button.AutomationId);
        }

        [TestMethod]
        public void ShouldGetNameProperty()
        {
            var window = new UIWindow("@Name='QuickUIT Test Application'");
            UIControl button = window.UIControl("[@ControlType='Button'][@Name='Button']");
            Assert.AreEqual("Button", button.Name);
        }

        [TestMethod]
        public void ShouldGetIsEnabledProperty()
        {
            var window = new UIWindow("@Name='QuickUIT Test Application'");
            UIControl button = window.UIControl("[@ControlType='Button'][@Name='Button']");
            Assert.IsTrue(button.IsEnabled);
        }

        [TestMethod]
        public void ShouldGetControlTypeProperty()
        {
            var window = new UIWindow("@Name='QuickUIT Test Application'");
            UIControl button = window.UIControl("[@ControlType='Button'][@Name='Button']");
            Assert.AreEqual(ControlType.Button, button.ControlType);
        }

        [TestMethod]
        public void ShouldGetHasKeyboardFocusProperty()
        {
            var window = new UIWindow("@Name='QuickUIT Test Application'");
            UIControl button = window.UIControl("[@ControlType='Button'][@Name='Button']");
            Assert.IsFalse(button.HasKeyboardFocus);
        }

        [TestMethod]
        public void ShouldGetClassNameProperty()
        {
            var window = new UIWindow("@Name='QuickUIT Test Application'");
            UIControl button = window.UIControl("[@ControlType='Button'][@Name='Button']");
            Assert.AreEqual("Button", button.ClassName);
        }

        [TestMethod]
        public void ShouldGetBoundingRectangleProperty()
        {
            var window = new UIWindow("@Name='QuickUIT Test Application'");
            UIControl button = window.UIControl("[@ControlType='Button'][@Name='Button']");
            Assert.AreNotEqual(new Rect(), button.BoundingRectangle);
        }

        [TestMethod]
        public void ShouldGetIsOffscreenProperty()
        {
            var window = new UIWindow("@Name='QuickUIT Test Application'");
            UIControl button = window.UIControl("[@ControlType='Button'][@Name='Button']");
            Assert.IsFalse(button.IsOffscreen);
        }

        [TestMethod]
        public void ShouldGetIsVisibleProperty()
        {
            var window = new UIWindow("@Name='QuickUIT Test Application'");
            UIControl button = window.UIControl("[@ControlType='Button'][0]");
            Assert.AreEqual("Button", button.Name);
            Assert.IsTrue(button.IsVisible);
        }

        [TestMethod]
        public void ShouldGetItemStatusProperty()
        {
            var window = new UIWindow("@Name='QuickUIT Test Application'");
            UIControl button = window.UIControl("[@ControlType='Button'][@Name='Button']");
            Assert.AreEqual(String.Empty, button.ItemStatus);
        }

        [TestMethod]
        public void ShouldGetHelpTextProperty()
        {
            var window = new UIWindow("@Name='QuickUIT Test Application'");
            UIControl button = window.UIControl("[@ControlType='Button'][@Name='Button']");
            Assert.AreEqual("Test Tooltip", button.HelpText);
        }

        [TestMethod]
        public void ShouldGetClickablePoint()
        {
            var window = new UIWindow("@Name='QuickUIT Test Application'");
            UIControl button = window.UIControl("[@ControlType='Button'][@Name='Button']");
            Assert.AreNotEqual(new Point(), button.ClickablePoint);
        }

        [TestMethod]
        public void ShouldClickOnControl()
        {
            var window = new UIWindow("@Name='QuickUIT Test Application'");
            UIControl button = window.UIControl("[@ControlType='Button'][@Name='Button']");
            button.Click();
        }

        [TestMethod]
        public void ShouldDoubleClickOnControl()
        {
            var window = new UIWindow("@Name='QuickUIT Test Application'");
            UIControl button = window.UIControl("[@ControlType='Button'][@Name='Button']");
            button.DoubleClick();
        }

        [TestMethod]
        public void ShouldPressAndReleaseMouseOnControl()
        {
            var window = new UIWindow("@Name='QuickUIT Test Application'");
            UIControl button = window.UIControl("[@ControlType='Button'][@Name='Button']");
            button.MousePress(Mouse.MouseButton.Left);
            button.MouseRelease(Mouse.MouseButton.Left);
        }

        [TestMethod]
        public void ShouldHoverOverControl()
        {
            var window = new UIWindow("@Name='QuickUIT Test Application'");
            UIControl button = window.UIControl("[@ControlType='Button'][@Name='Button']");
            button.MouseHover();
        }

        [TestMethod]
        public void ShouldSetFocus()
        {
            var window = new UIWindow("@Name='QuickUIT Test Application'");
            UIControl button = window.UIControl("[@ControlType='Button'][@Name='Button']");
            button.SetFocus();
            Assert.IsTrue(button.HasKeyboardFocus);
        }

        [TestMethod]
        public void ShouldOpenContextMenu()
        {
            var window = new UIWindow("@Name='QuickUIT Test Application'");
            UIControl textBox = window.UIControl("[@ControlType='Edit'][@AutomationId='textBox3']");
            textBox.OpenContextMenu();
            var contextMenu = window.UIControl("@ClassName='ContextMenu'");
            Assert.IsNotNull(contextMenu);
        }

        [TestMethod]
        [ExpectedException(typeof(UIControlNotFoundException))]
        public void ShouldThrowNotFoundExceptionForNonExistentObject()
        {
            var window = new UIWindow("@Name='QuickUIT Test Application'");
            AutomationConfiguration.Current.ObjectSearchTime = 1000;
            try
            {
                window.UIControl("@AutomationId='NoControl'");
            }
            catch (UIControlNotFoundException ex)
            {
                Assert.AreEqual("Could not find '//UIControl[@AutomationId='NoControl']'", ex.Message);
                throw;
            }
        }

        [TestMethod]
        public void ShouldGetDockPosition()
        {
            var window = new UIWindow("@Name='QuickUIT Test Application'");
            UIControl menuBar = window.UIControl("[@ControlType='MenuBar']");
            Assert.IsFalse(menuBar.DockPosition.HasValue); 
        }

        [TestMethod]
        public void ShouldGetExpandCollapseState()
        {
            var window = new UIWindow("@Name='QuickUIT Test Application'");
            UIControl comboBox = window.UIControl("[@ControlType='ComboBox']");
            Assert.IsTrue(comboBox.ExpandCollapseState.HasValue); 
            Assert.AreEqual(ExpandCollapseState.Collapsed, comboBox.ExpandCollapseState.GetValueOrDefault());
        }

        [TestMethod]
        public void ShouldGetToggleState()
        {
            var window = new UIWindow("@Name='QuickUIT Test Application'");
            UIControl checkbox = window.UIControl("[@ControlType='CheckBox']");
            Assert.IsTrue(checkbox.ToggleState.HasValue);
            Assert.AreEqual(ToggleState.Off, checkbox.ToggleState.GetValueOrDefault());
        }

        [TestMethod]
        public void ShouldGetRowOrColumnMajor()
        {
            var window = new UIWindow("@Name='QuickUIT Test Application'");
            UIControl dataGrid = window.UIControl("[@AutomationId='dataGrid1']");
            Assert.IsTrue(dataGrid.RowOrColumnMajor.HasValue);
            Assert.AreEqual(RowOrColumnMajor.RowMajor, dataGrid.RowOrColumnMajor.GetValueOrDefault());
        }

        [TestMethod]
        public void ShouldGetColumnCount()
        {
            var window = new UIWindow("@Name='QuickUIT Test Application'");
            UIControl dataGrid = window.UIControl("[@AutomationId='dataGrid1']");
            Assert.AreEqual(4, dataGrid.ColumnCount);
        }

        [TestMethod]
        public void ShouldGetRowCount()
        {
            var window = new UIWindow("@Name='QuickUIT Test Application'");
            UIControl dataGrid = window.UIControl("[@AutomationId='dataGrid1']");
            Assert.AreEqual(6, dataGrid.RowCount);
        }

        [TestMethod]
        public void ShouldGetColumn()
        {
            var window = new UIWindow("@Name='QuickUIT Test Application'");
            UIControl dataGridCell = window.UIControl("[@AutomationId='dataGrid1']").UIDataItem().UIControl("@ClassName='DataGridCell'");
            Assert.AreEqual(0, dataGridCell.Column);
        }

        [TestMethod]
        public void ShouldGetRow()
        {
            var window = new UIWindow("@Name='QuickUIT Test Application'");
            UIControl dataGridCell = window.UIControl("[@AutomationId='dataGrid1']").UIDataItem().UIControl("@ClassName='DataGridCell'");
            Assert.AreEqual(0, dataGridCell.Row);
        }

        [TestMethod]
        public void ShouldGetColumnSpan()
        {
            var window = new UIWindow("@Name='QuickUIT Test Application'");
            UIControl dataGridCell = window.UIControl("[@AutomationId='dataGrid1']").UIDataItem().UIControl("@ClassName='DataGridCell'");
            Assert.AreEqual(1, dataGridCell.ColumnSpan);
        }

        [TestMethod]
        public void ShouldGetRowSpan()
        {
            var window = new UIWindow("@Name='QuickUIT Test Application'");
            UIControl dataGridCell = window.UIControl("[@AutomationId='dataGrid1']").UIDataItem().UIControl("@ClassName='DataGridCell'");
            Assert.AreEqual(1, dataGridCell.RowSpan);
        }

        [TestMethod]
        public void ShouldGetLargeChange()
        {
            var window = new UIWindow("@Name='QuickUIT Test Application'");
            UIControl slider = window.UIControl("@ControlType='Slider'"); 
            Assert.AreEqual(1, slider.LargeChange);
        }

        [TestMethod]
        public void ShouldGetSmallChange()
        {
            var window = new UIWindow("@Name='QuickUIT Test Application'");
            UIControl slider = window.UIControl("@ControlType='Slider'");
            Assert.AreEqual(0.1, slider.SmallChange);
        }

        [TestMethod]
        public void ShouldGetMaximum()
        {
            var window = new UIWindow("@Name='QuickUIT Test Application'");
            UIControl slider = window.UIControl("@ControlType='Slider'");
            Assert.AreEqual(10, slider.Maximum);
        }

        [TestMethod]
        public void ShouldGetMinimum()
        {
            var window = new UIWindow("@Name='QuickUIT Test Application'");
            UIControl slider = window.UIControl("@ControlType='Slider'");
            Assert.AreEqual(0, slider.Minimum);
        }

        [TestMethod]
        public void ShouldGetRangeValue()
        {
            var window = new UIWindow("@Name='QuickUIT Test Application'");
            UIControl slider = window.UIControl("@ControlType='Slider'");
            Assert.AreEqual(0, slider.RangeValue);
        }

        [TestMethod]
        public void ShouldGetHorizontallyScrollable()
        {
            var window = new UIWindow("@Name='QuickUIT Test Application'");
            UIControl listBox = window.UIControl("@AutomationId='listBox1'");
            Assert.IsFalse(listBox.HorizontallyScrollable);
        }

        [TestMethod]
        public void ShouldGetVerticallyScrollable()
        {
            var window = new UIWindow("@Name='QuickUIT Test Application'");
            UIControl listBox = window.UIControl("@AutomationId='listBox1'");
            Assert.IsTrue(listBox.VerticallyScrollable);
        }

        [TestMethod]
        public void ShouldGetHorizontalScrollPercent()
        {
            var window = new UIWindow("@Name='QuickUIT Test Application'");
            UIControl listBox = window.UIControl("@AutomationId='listBox1'");
            Assert.AreEqual(-1, listBox.HorizontalScrollPercent);
        }

        [TestMethod]
        public void ShouldGetVerticalScrollPercent()
        {
            var window = new UIWindow("@Name='QuickUIT Test Application'");
            UIControl listBox = window.UIControl("@AutomationId='listBox1'");
            Assert.AreEqual(0, listBox.VerticalScrollPercent);
        }

        [TestMethod]
        public void ShouldGetHorizontalViewSize()
        {
            var window = new UIWindow("@Name='QuickUIT Test Application'");
            UIControl listBox = window.UIControl("@AutomationId='listBox1'");
            Assert.AreEqual(100, listBox.HorizontalViewSize);
        }

        [TestMethod]
        public void ShouldGetVerticalViewSize()
        {
            var window = new UIWindow("@Name='QuickUIT Test Application'");
            UIControl listBox = window.UIControl("@AutomationId='listBox1'");
            Assert.AreEqual(60, listBox.VerticalViewSize);
        }
        
        [TestMethod]
        public void ShouldGetIsSelected()
        {
            var window = new UIWindow("@Name='QuickUIT Test Application'");
            UIControl listItem = window.UIControl("@AutomationId='listBox1'").UIControl("@ControlType='ListItem'");
            Assert.IsFalse(listItem.IsSelected);
        }

        [TestMethod]
        public void ShouldGetCanSelectMultiple()
        {
            var window = new UIWindow("@Name='QuickUIT Test Application'");
            UIControl listBox = window.UIControl("@AutomationId='listBox1'");
            Assert.IsFalse(listBox.CanSelectMultiple);
        }

        [TestMethod]
        public void ShouldGetIsSelectionRequired()
        {
            var window = new UIWindow("@Name='QuickUIT Test Application'");
            UIControl listBox = window.UIControl("@AutomationId='listBox1'");
            Assert.IsFalse(listBox.IsSelectionRequired);
        }

        [TestMethod]
        public void ShouldGetDocumentRange()
        {
            var window = new UIWindow("@Name='QuickUIT Test Application'");
            UIControl passwordBox = window.UIControl("@AutomationId='passwordBox1'");
            Assert.IsNotNull(passwordBox.DocumentRange);
        }

        [TestMethod]
        public void ShouldGetIsReadOnly()
        {
            var window = new UIWindow("@Name='QuickUIT Test Application'");
            UIControl textBox = window.UIControl("@AutomationId='textBox4'");
            Assert.IsTrue(textBox.IsReadOnly);
        }

        [TestMethod]
        public void ShouldGetValue()
        {
            var window = new UIWindow("@Name='QuickUIT Test Application'");
            UIControl textBox = window.UIControl("@AutomationId='textBox4'");
            Assert.AreEqual("Read-only", textBox.Value);
        }

        [TestMethod]
        public void ShouldTypeText()
        {
            var window = new UIWindow("@Name='QuickUIT Test Application'");
            UIControl textBox = window.UIControl("@AutomationId='textBox3'");
            textBox.SetFocus();
            textBox.TypeText("123");
            Assert.AreEqual("123", textBox.Value);
        }

        [TestMethod]
        public void ShouldExpandControl()
        {
            var window = new UIWindow("@Name='QuickUIT Test Application'");
            UIControl comboBox = window.UIControl("@ControlType='ComboBox'");
            comboBox.Expand();
            Assert.AreEqual(ExpandCollapseState.Expanded, comboBox.ExpandCollapseState.GetValueOrDefault());
        }

        [TestMethod]
        public void ShouldCollapseControl()
        {
            var window = new UIWindow("@Name='QuickUIT Test Application'");
            UIControl comboBox = window.UIControl("@ControlType='ComboBox'");
            comboBox.Expand();
            Assert.AreEqual(ExpandCollapseState.Expanded, comboBox.ExpandCollapseState.GetValueOrDefault());
            comboBox.Collapse();
            Assert.AreEqual(ExpandCollapseState.Collapsed, comboBox.ExpandCollapseState.GetValueOrDefault());
        }

        [TestMethod]
        public void ShouldInvokeControl()
        {
            var window = new UIWindow("@Name='QuickUIT Test Application'");
            UIControl button = window.UIControl("@AutomationId='button1'");
            button.Invoke();
        }

        [TestMethod]
        public void ShouldGetItem()
        {
            var window = new UIWindow("@Name='QuickUIT Test Application'");
            UIControl dataGrid = window.UIControl("[@AutomationId='dataGrid1']");
            var item = dataGrid.GetItem(0, 0); 
            Assert.IsNotNull(item);
        }

        [TestMethod]
        public void ShouldScrollControl()
        {
            var window = new UIWindow("@Name='QuickUIT Test Application'");
            UIControl listBox = window.UIControl("@AutomationId='listBox1'");
            listBox.Scroll(ScrollAmount.NoAmount, ScrollAmount.SmallIncrement);
        }

        [TestMethod]
        public void ShouldScrollVerticallyControl()
        {
            var window = new UIWindow("@Name='QuickUIT Test Application'");
            UIControl listBox = window.UIControl("@AutomationId='listBox1'");
            listBox.ScrollVertically(ScrollAmount.LargeIncrement);
        }

        [TestMethod]
        [ExpectedException(typeof(InvalidOperationException))]
        public void ShouldThrowExceptionOnScrollHorizontallyForUnsupportedControl()
        {
            var window = new UIWindow("@Name='QuickUIT Test Application'");
            UIControl listBox = window.UIControl("@AutomationId='listBox1'");
            listBox.ScrollHorizontally(ScrollAmount.LargeIncrement);
        }

        [TestMethod]
        public void ShouldSetScrollPercent()
        {
            var window = new UIWindow("@Name='QuickUIT Test Application'");
            UIControl listBox = window.UIControl("@AutomationId='listBox1'");
            listBox.SetScrollPercent(ScrollPattern.NoScroll, 100.0);
        }

        [TestMethod]
        public void ShouldScrollToTop()
        {
            var window = new UIWindow("@Name='QuickUIT Test Application'");
            UIControl listBox = window.UIControl("@AutomationId='listBox1'");
            listBox.ScrollToTop();
        }

        [TestMethod]
        public void ShouldScrollIntoView()
        {
            var window = new UIWindow("@Name='QuickUIT Test Application'");
            UIControl listItem = window.UIControl("@Name='List Item 7'");
            listItem.ScrollIntoView();
        }

        [TestMethod]
        public void ShouldSelectControl()
        {
            var window = new UIWindow("@Name='QuickUIT Test Application'");
            UIControl listItem = window.UIControl("@Name='List Item 1'");
            listItem.Select();
            Assert.IsTrue(listItem.IsSelected); 
        }

        [TestMethod]
        public void ShouldAddToSelection()
        {
            var window = new UIWindow("@Name='QuickUIT Test Application'");
            UIControl listItem = window.UIControl("@Name='List Item 1'");
            listItem.AddToSelection();
            Assert.IsTrue(listItem.IsSelected);
        }

        [TestMethod]
        public void ShouldRemoveFromSelection()
        {
            var window = new UIWindow("@Name='QuickUIT Test Application'");
            UIControl listItem = window.UIControl("@Name='List Item 1'");
            listItem.AddToSelection();
            Assert.IsTrue(listItem.IsSelected);
            listItem.RemoveFromSelection();
            Assert.IsFalse(listItem.IsSelected);
        }

        [TestMethod]
        public void ShouldGetSelection()
        {
            var window = new UIWindow("@Name='QuickUIT Test Application'");
            UIControl listBox = window.UIControl("@AutomationId='listBox1'");
            var selection = listBox.GetSelection(); 
            Assert.AreEqual(0, selection.Length);
        }

        [TestMethod]
        public void ShouldGetSelectionContainer()
        {
            var window = new UIWindow("@Name='QuickUIT Test Application'");
            UIControl listItem = window.UIControl("@Name='List Item 1'");
            var container = listItem.GetSelectionContainer(); 
            Assert.IsNotNull(container);
            Assert.AreEqual(ControlType.List, container.Current.ControlType);
        }

        [TestMethod]
        public void ShouldGetColumnHeaders()
        {
            var window = new UIWindow("@Name='QuickUIT Test Application'");
            UIControl dataGrid = window.UIControl("[@AutomationId='dataGrid1']");
            Assert.AreEqual(4,  dataGrid.GetColumnHeaders().Length);
        }

        [TestMethod]
        public void ShouldGetRowHeaders()
        {
            var window = new UIWindow("@Name='QuickUIT Test Application'");
            UIControl dataGrid = window.UIControl("[@AutomationId='dataGrid1']");
            Assert.AreEqual(6, dataGrid.GetRowHeaders().Length);
        }

        [TestMethod]
        public void ShouldGetColumnHeaderItems()
        {
            var window = new UIWindow("@Name='QuickUIT Test Application'");
            UIControl cell = window.UIControl("[@AutomationId='dataGrid1']").UIControl("@ClassName='DataGridCell'");
            Assert.AreEqual(1, cell.GetColumnHeaderItems().Length);
        }

        [TestMethod]
        public void ShouldGetRowHeaderItems()
        {
            var window = new UIWindow("@Name='QuickUIT Test Application'");
            UIControl cell = window.UIControl("[@AutomationId='dataGrid1']").UIControl("@ClassName='DataGridCell'");
            Assert.AreEqual(1, cell.GetRowHeaderItems().Length);
        }

        [TestMethod]
        public void ShouldGetContainingGrid()
        {
            var window = new UIWindow("@Name='QuickUIT Test Application'");
            UIControl cell = window.UIControl("[@AutomationId='dataGrid1']").UIControl("@ClassName='DataGridCell'");
            var containingGrid = cell.GetContainingGrid(); 
            Assert.IsNotNull(containingGrid);
            Assert.AreEqual(ControlType.DataGrid, containingGrid.Current.ControlType);
        }

        [TestMethod]
        public void ShouldGetTextSelection()
        {
            var window = new UIWindow("@Name='QuickUIT Test Application'");
            UIControl textBox = window.UIControl("[@ControlType='Edit'][@AutomationId='textBox3']");
            var textSelection = textBox.GetTextSelection(); 
            Assert.IsNotNull(textSelection);
            Assert.AreEqual(1, textSelection.Length);
        }

        [TestMethod]
        public void ShouldGetVisibleRanges()
        {
            var window = new UIWindow("@Name='QuickUIT Test Application'");
            UIControl textBox = window.UIControl("[@ControlType='Edit'][@AutomationId='textBox3']");
            var visibleRanges = textBox.GetVisibleRanges();
            Assert.IsNotNull(visibleRanges);
            Assert.AreEqual(1, visibleRanges.Length);
        }

        [TestMethod]
        public void ShouldGetToggleControl()
        {
            var window = new UIWindow("@Name='QuickUIT Test Application'");
            UIControl checkbox = window.UIControl("[@ControlType='CheckBox']");
            Assert.AreEqual(ToggleState.Off, checkbox.ToggleState.GetValueOrDefault());
            checkbox.Toggle();
            Assert.AreEqual(ToggleState.On, checkbox.ToggleState.GetValueOrDefault());
        }

        [TestMethod]
        public void ShouldGetToggleOnControl()
        {
            var window = new UIWindow("@Name='QuickUIT Test Application'");
            UIControl checkbox = window.UIControl("[@ControlType='CheckBox']");
            Assert.AreEqual(ToggleState.Off, checkbox.ToggleState.GetValueOrDefault());
            checkbox.ToggleOn();
            Assert.AreEqual(ToggleState.On, checkbox.ToggleState.GetValueOrDefault());
        }

        [TestMethod]
        public void ShouldGetToggleOffControl()
        {
            var window = new UIWindow("@Name='QuickUIT Test Application'");
            UIControl checkbox = window.UIControl("[@ControlType='CheckBox']");
            Assert.AreEqual(ToggleState.Off, checkbox.ToggleState.GetValueOrDefault());
            checkbox.ToggleOn();
            Assert.AreEqual(ToggleState.On, checkbox.ToggleState.GetValueOrDefault());
            checkbox.ToggleOff();
            Assert.AreEqual(ToggleState.Off, checkbox.ToggleState.GetValueOrDefault());
        }

        [TestMethod]
        public void ShouldSetValue()
        {
            var window = new UIWindow("@Name='QuickUIT Test Application'");
            UIControl textBox = window.UIControl("[@ControlType='Edit'][@AutomationId='textBox3']");
            textBox.SetValue("123");
            Assert.AreEqual("123", textBox.Value);
        }

        [TestMethod]
        public void ShouldSetRangeValue()
        {
            var window = new UIWindow("@Name='QuickUIT Test Application'");
            UIControl slider = window.UIControl("@ControlType='Slider'");
            slider.SetRangeValue(1.0);
            Assert.AreEqual(1, slider.RangeValue);
        }

        [TestCleanup]
        public void TestTeardown()
        {
            AutomationConfiguration.Current.Reset();
            _baseState.Cleanup();
        }
    }
}